package org.itboys.mobile.service.mysql.web.product;


import org.apache.commons.lang3.StringUtils;
import org.itboys.admin.service.lasted.SundayUploadService;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.framework.resource.ResourceHolder;
import org.itboys.mobile.entity.mysql.product.SundayProductBrand;
import org.itboys.mysql.service.BaseMySqlService;
import org.itboys.param.PageResult;
import org.itboys.param.ParamUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：圣代_商品_品牌_service_web
 */

@Service
public class SundayProductBrandService extends BaseMySqlService<SundayProductBrand> {
	@Autowired
	private SundayUploadService uploadService;
	@Autowired
	private ResourceHolder resourceHolder;

	/**
	 * 分页获取品牌
	 * @param request
	 * @return
	 */
	public PageResult<SundayProductBrand> selectProductBrand(HttpServletRequest request){
		Map<String,Object> param = ParamUtil.packageMysqlPageParam(request,"name","categoryName");
		return super.selectPage(param);
	}

	/**
	 * 新增或修改品牌
	 * @param brand
	 * @param imageFile
	 * @throws Exception
	 */
	public void save(SundayProductBrand brand,MultipartFile imageFile) throws Exception{
		Map<String, String> map = uploadService.uploadSingle(imageFile);
		if(StringUtils.isNotEmpty(map.get(uploadService.UPLOAD_HALF_PATH))){
			brand.setImage(map.get(uploadService.UPLOAD_HALF_PATH));
		}
		if(LongUtil.isNotZreo(brand.getId())){
			super.update(brand);
		}else{
			super.insert(brand);
		}
	}

}
